<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      height: 40px;
      width: 400px;
      background-color: #e7c3c3;
      margin-top: 10px;
    }
  </style>
</head>
<body>
  <div id="app">
    {{num}}
    <br>
    <button @click="doubleNum = 300">给计算属性赋值</button>
    {{doubleNum}}
  </div>
  
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          num: 10
        }
      },
      computed: {
        /*
        doubleNum(){
          return this.num * 2
        }
        */
        doubleNum: {
          get(){
            return this.num * 2
          },
          // 当我们给计算属性赋值时  setter触发
          set(newVal){
            console.log('给计算属性赋值了', newVal);
            this.num = newVal / 2;
          }
        }
      }
    })
    
    app.mount('#app')
  </script>
</body>
</html>